package com.bufbomb.datastore.admin;

import java.io.IOException;
import javax.servlet.http.*;
import com.google.appengine.api.users.UserService;
import com.google.appengine.api.users.UserServiceFactory;

@SuppressWarnings("serial")
public class LoginServlet extends HttpServlet {
	public void doGet(HttpServletRequest req, HttpServletResponse resp)
		throws IOException {
		UserService userService = UserServiceFactory.getUserService();
		if (!userService.isUserLoggedIn()) 
		{
			resp.sendRedirect(userService.createLoginURL("/index.jsp"));
			return;
		}
		else if(!userService.isUserAdmin()) 
		{
			resp.setContentType("text/plain");
			resp.getWriter().println("You should sign in as administrator to upload flash.<br />");
			resp.getWriter().println("<a href='" + userService.createLogoutURL("/index.jsp") + "'> sign out </a>");
		}else
		{
			resp.getWriter().println("You have signed in correctly.<br />");
			resp.getWriter().println("<a href='" + userService.createLogoutURL("/index.jsp") + "'> sign out </a>");
		}
	}
}
